package com.zr.userlogin.controller;



import com.zr.userlogin.pojo.LoginVo1;
import com.zr.userlogin.pojo.registerVo;
import com.zr.userlogin.service.UserService;

import com.zr.util.ResultVOBuilder;
import com.zr.util.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

/**
 * Created by jiangping on 2019/6/21.
 */
@RestController
public class UserController {
    @Autowired
    private UserService userService;

    /**
     * 注册
     */
    @PostMapping("register")
    public ResultVo register(@RequestBody @Valid registerVo registerVo, BindingResult bindingResult){
        if (bindingResult.hasErrors()){

            return ResultVOBuilder.error(bindingResult.getFieldError().getDefaultMessage(),"500");
        }
        return userService.register(registerVo);
    }

    /**
     * 登录
     */
    @PostMapping("login")
    public ResultVo login(@RequestBody @Valid LoginVo1 loginVo1, HttpServletRequest request, BindingResult bindingResult){
        if (bindingResult.hasErrors()){

            return ResultVOBuilder.error(bindingResult.getFieldError().getDefaultMessage(),"500");
        }
        return userService.login(loginVo1,request);
    }

    /**
     * 邀请码
     */
    /*@GetMapping("inputInvitationCode")
    public ResultVo inputInvitationCode(@RequestParam("invitationCode") String invitationCode){
        return userService.inputInvitationCode(invitationCode);
    }*/
}

